//process.h

#ifndef PROCESS_H
#define PROCESS_H

#include "list.h"
#include "thread.h"
#include "addrspace.h"
//#include "system.h"

/*****************************

ProcessTableThread Class:

Represents a thread of a process in the process
table.
NOTE: the process here is to call methods on all 
the 'top level hierarchy' of threads then the 
methods will propogate down to the children
through recursive calls. 

*****************************/
class ProcessTableThread
{
 public:
  ProcessTableThread(Thread *thread);         //default constructor
  ~ProcessTableThread();                      //default destructor
  Thread* getMyThread();                     //returns point to thread
                                             //this processTableThread represent
  int getListSize();                        
  int* getbitMapLoc();                      
  int* getpageTblLoc();               
  void setStackReg(int v);
  int getStackReg();
               
 private:
  Thread *mythread;//thread this data structure represents
  int bitMapLoc[8];//8 location in the main memory bitmap for this thread
  int pageTblLoc[8];//8 locations in the page table for this thread
  int stackReg;
  
};


/*****************************

Process Class:

Represents a process and contains a process ID,
address space for the process, and a list of 
all threads executed in the process.

*****************************/

class Process {
 public:
  Process(AddrSpace * newspace);
  ~Process();
  int getID();
  AddrSpace* getAddrSpace();
  ProcessTableThread*getThread(Thread *thread);
  void addThread(Thread * newthread);                //add thread to process
  void removeThread(Thread * oldthread);             //remove thread from process
  int getNumActiveThreads();                        
  void Clear(int i);                                 
  
  //methods to add and destroy locks
  void addLock(int i);              
  void removeLock(int i);

  //methods to add and destroy condition variables
  void addCondition(int i);
  void removeCondition(int i);

  //debug method to print out threads still in process
  void printThreads();
  //debug method to print out this process's lock ints
  void printLocks();
  //debug mehtod to print out this process's condition ints
  void printConditions();
  static int idCount;
  
  char* Name;//way to identify thread for debugging

 private:
  int id;
  int numActiveThreads;
  AddrSpace* space;
  List *threads;
  //Thread *mainThread;
  Lock *processLock;
  //collection of ints of this processes locks
  List *myLocks;
  //collection of ints of this processes condition variables
  List *myConditions;

#ifdef NETWORK
 private:
  //Mail box number for the process in the nachos client, need a different one for each process
  int mailbox;

 public:
  //Set the mailbox number
  void setMailBox(int num);
  //Return the mailbox number
  int getMailBox();

#endif

};

#endif // PROCESS_H
